home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 52 / Amiga Format AFCD52 (Issue 136, May 2000).iso / -serious- / programming / other / littelcomp / r5 / lc / examples / ptrs.library.l < prev    next >
Text File  |  2000-02-28  |  2KB  |  69 lines

  1. //
  2.  
  3. // LITTEL v0.12 Example of using PTRs ..rewritten to 0.13b, 0.16b//
  4. // extended to shared library, just for fun  //
  5.  
  6. #mode LIBRARY 37 1 "ptrs.library" "ptrs.library by me 99"
  7. #link library.lib
  8.  
  9. #fdef bubblesort2
  10. #fdef fill_longarray_with_words
  11. #endfdef _PtrsBase
  12.  
  13.  
  14. #equ Useful 10
  15. #equ NotUseful 0
  16. #equ LongSize 4
  17. #equ WordSize 2
  18.  
  19.     // remember : youre only allowed to use D0-D5/A0-A3 ! //
  20.     // if itsnot a special case like, just before CALLing or DOPROCing //
  21.  
  22. PROC bubblesort2 // Array Of Long -> D0, Len -> D1
  23.    VAR end           // declare a variabel (local)
  24.    CODESTART
  25.    COPY D0       end
  26.    ADD  D1       end
  27.    DEC  LongSize end
  28.    REPEAT
  29.       COPY NotUseful D2
  30.       COPY D0 A0
  31.       REPEAT
  32.          IF A0[] GT A0[].LongSize   // GT : Greater Then
  33.             SWAP A0[]   A0[].LongSize // Aaah..mmm.. swap.. :)
  34.             COPY Useful D2
  35.          ELSE
  36.          ENDIF
  37.          INC LongSize A0
  38.       ENDREPEAT A0 EQ end
  39.    ENDREPEAT D2 EQ NotUseful
  40. ENDPROC
  41.  
  42.    // NOTE : for speed reasons we use Ax and Dx Registers here..  //
  43.    // but we could have done it in exactly the same way usin just //
  44.    // local vars, they can also work as PTRs : myvar[].           //
  45.    // Remeber!  : You are only Allowed to Use D0-D5, A0-A3!       //
  46.    // but hey.. variables arent THAT slow anyway ..               //
  47.  
  48.    // another example.. //
  49.  
  50. PROC fill_longarray_with_words // longarray -> D0, wordarray -> D1, nrofwords -> D2
  51.    VAR larray          // local vars
  52.    VAR warray          // always LONGs as u know, I hope.
  53.    VAR len             //
  54.    CODESTART
  55.    COPY D0 larray      // copying some regs to som vars..
  56.    COPY D1 warray      //
  57.    COPY D2 len         //
  58.  
  59.    WHILE len GT 0                // while len > 0
  60.       COPY warray[W]  larray[L]
  61.       INC WordSize    warray   // add 2 to warray
  62.       INC LongSize    larray   // add 4 to larray
  63.       DEC 1           len      // sub 1 from len
  64.    ENDWHILE 
  65. ENDPROC
  66.  
  67. END
  68.   
  69.